package com.teng.mylibrary.util

import android.content.Context
import android.content.Intent
import android.net.ParseException
import android.net.Uri
import java.text.DecimalFormat
import java.text.NumberFormat

import java.io.*


/**
  * Description:    工具类
  * Author:         liuteng
  * CreateDate:     2022年4月24日
  * UpdateRemark:   更新说明
 */
object Util {

    fun getFormatDate(year: Int, month: Int, day: Int): String {
        return StringBuilder()
            .append(String.format("%02d", year))
            .append("-")
            .append(String.format("%02d", month))
            .append("-")
            .append(String.format("%02d", day))
            .toString()
    }

    fun getFormatDatePh(year: Int, month: Int, day: Int): String {
        return StringBuilder()
            .append(String.format("%02d", year))
            .append(String.format("%02d", month))
            .append(String.format("%02d", day))
            .toString()
    }

    fun getFormatTime(hour: Int, minute: Int): String {
        return StringBuilder()
            .append(String.format("%02d", hour))
            .append(":")
            .append(String.format("%02d", minute))
            .toString()
    }

    /**
     * 通知系统相册刷新照片
     */
    fun refreshSystemAlbum(context: Context, file: File) {
        val intent = Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE)
        val uri = Uri.fromFile(file)
        intent.data = uri
        context.sendBroadcast(intent)
    }

    fun isEmpty(str: String?): Boolean {
        return str == null || str.trim { it <= ' ' }.isEmpty()
    }

    /**
     * 字符串 千位符
     *
     * @param num
     * @return
     */
    fun num2thousand(num: String?): String? {
        var numStr = ""
        if (isEmpty(num)) {
            return numStr
        }
        val nf: NumberFormat = NumberFormat.getInstance()
        try {
            val df = DecimalFormat("#,###")
            numStr = df.format(nf.parse(num))
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return numStr
    }

    /**
     * 字符串 千位符  保留两位小数点后两位
     *
     * @param num
     * @return
     */
    fun num2thousand00(num: String?): String? {
        var numStr = ""
        if (isEmpty(num)) {
            return numStr
        }
        val nf: NumberFormat = NumberFormat.getInstance()
        try {
            val df = DecimalFormat("#,##0.00")
            numStr = df.format(nf.parse(num))
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return numStr
    }

    fun getDanJuStatus(status: String?): String? {
        when (status) {
            "A" -> {
                return "创建"
            }
            "B" -> {
                return "审核中"
            }
            "C" -> {
                return "已审核"
            }
            "D" -> {
                return "重新审核"
            }
            else -> {
                return null
            }
        }
    }


}